import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export default new Router({
    base: "/",
    mode: 'hash',
    routes: [
        // 首页
        {
            path: '/',
            name: 'Index',
            component: resolve => require(['@/pages/index/index'], resolve)
        },
        // 好物推荐
        {
            path: '/best',
            name: 'Best',
            component: resolve => require(['@/pages/index/best'], resolve)
        },
        // 虚拟商品详情
        {
            path: '/detail',
            name: 'Detail',
            component: resolve => require(['@/pages/index/detail'], resolve)
        },
        // 实物商品详情
        {
            path: '/goodsDetail',
            name: 'GoodsDetail',
            component: resolve => require(['@/pages/index/goodsDetail'], resolve)
        },
        // 分类
        {
            path: '/classify',
            name: 'Classify',
            meta: {
                keepAlive: true
            },
            component: resolve => require(['@/pages/classify/classify'], resolve)
        },
        // 购物车
        {
            path: '/car',
            name: 'Car',
            component: resolve => require(['@/pages/car/car'], resolve)
        },
        // 我的
        {
            path: '/center',
            name: 'Center',
            component: resolve => require(['@/pages/center/center'], resolve)
        },
        // 我的收藏
        {
            path: '/collect',
            name: 'Collect',
            component: resolve => require(['@/pages/center/collect'], resolve)
        },
        // 意见反馈
        {
            path: '/feedback',
            name: 'Feedback',
            component: resolve => require(['@/pages/center/feedback'], resolve)
        },
        // 关于我们
        {
            path: '/aboutUs',
            name: 'AboutUs',
            component: resolve => require(['@/pages/center/aboutUs'], resolve)
        },
        // 分类页
        {
            path: '/iclassify',
            name: 'Iclassify',
            component: resolve => require(['@/pages/index/classify'], resolve)
        },
        // 搜索页
        {
            path: '/search',
            name: 'Search',
            component: resolve => require(['@/pages/index/search'], resolve)
        },
        // 搜索结果
        {
            path: '/result/:id',
            name: 'Result',
            component: resolve => require(['@/pages/index/result'], resolve)
        },
        // 核销订单
        {
            path: '/myOrder',
            name: 'MyOrder',
            component: resolve => require(['@/pages/center/myOrder'], resolve)
        },
        // 订单详情
        {
            path: '/orderDetail',
            name: 'OrderDetail',
            component: resolve => require(['@/pages/center/orderDetail'], resolve)
        },
        // 分销中心
        {
            path: '/distribution',
            name: 'Distribution',
            component: resolve => require(['@/pages/distribution/index'], resolve)
        },
        // 我的团队
        {
            path: '/team',
            name: 'Team',
            component: resolve => require(['@/pages/distribution/team'], resolve)
        },
        // 邀请好友
        {
            path: '/invite',
            name: 'Invite',
            component: resolve => require(['@/pages/distribution/invite'], resolve)
        },
        // 分销订单
        {
            path: '/disOrder',
            name: 'DisOrder',
            component: resolve => require(['@/pages/distribution/disOrder'], resolve)
        },
        // 佣金明细
        {
            path: '/earnDetail',
            name: 'EarnDetail',
            component: resolve => require(['@/pages/distribution/earnDetail'], resolve)
        },
        // 我要提现
        {
            path: '/cash',
            name: 'Cash',
            component: resolve => require(['@/pages/distribution/cash'], resolve)
        },
        // 规则
        {
            path: '/rules',
            name: 'Rules',
            component: resolve => require(['@/pages/distribution/rules'], resolve)
        },
        // 确认订单
        {
            path: '/confirmOrder',
            name: 'ConfirmOrder',
            component: resolve => require(['@/pages/index/confirmOrder'], resolve)
        },
        // 订单支付
        {
            path: '/orderPay',
            name: 'OrderPay',
            component: resolve => require(['@/pages/index/orderPay'], resolve)
        },
        // 支付结果
        {
            path: '/payResult',
            name: 'PayResult',
            component: resolve => require(['@/pages/index/payResult'], resolve)
        },
        // 核销码
        {
            path: '/writeoffcode',
            name: 'Writeoffcode',
            component: resolve => require(['@/pages/center/writeoffcode'], resolve)
        },
        //积分商城
        {
            path: '/mall',
            name: 'Mall',
            component: resolve => require(['@/pages/mall'], resolve)
        },
        // 收货地址
        {
            path: '/address',
            name: "Address",
            component: resolve => require(['@/pages/address'], resolve)
        },
        // 实物的确认订单
        {
            path: '/placeholder',
            name: 'Placeholder',
            component: resolve => require(['@/pages/index/placeholder'], resolve)
        },
        // 实物的确认订单
        {
            path: '/placeholder_1',
            name: 'Placeholder_1',
            component: resolve => require(['@/pages/index/placeholder_1'], resolve)
        },
        // 添加和编辑收货地址
        {
            path: '/addressAdd',
            name: 'AddressAdd',
            component: resolve => require(['@/pages/address/addressAdd'], resolve)
        },
        // 我的功能
        //物流订单
        {
            path: '/feature',
            name: 'Feature',
            component: resolve => require(['@/pages/feature'], resolve)
        },
        // 实物商品的详情
        {
            path: '/goodDetail',
            name: 'GoodDetail',
            component: resolve => require(['@/pages/feature/goodDetail'], resolve)
        },
        // 积分明细
        {
            path: '/scoreDetail',
            name: 'scoreDetail',
            component: resolve => require(['@/pages/mall/detail'], resolve)
        },
        // 积分商城兑换记录
        {
            path: '/mallRecord',
            name: 'MallRecord',
            component: resolve => require(['@/pages/mall/record'], resolve)
        },
        // 积分商品详情
        {
            path: '/mallDetail',
            name: 'MallDetail',
            component: resolve => require(['@/pages/mall/goodDetail'], resolve)
        },
        // 积分商品兑换成功
        {
            path: '/mallSuccess',
            name: 'MallSuccess',
            component: resolve => require(['@/pages/mall/success'], resolve)
        },
        // 评论界面
        {
            path: '/evaluate',
            name: 'Evaluate',
            component: resolve => require(['@/pages/index/evaluate'], resolve)
        },
        // 旅游达人
        {
            path: '/travel',
            name: 'Travel',
            component: resolve => require(['@/pages/travel'], resolve)
        },
        // 全部评价
        {
            path: '/evaluates',
            name: 'Evaluates',
            component: resolve => require(['@/pages/index/allEvaluate'], resolve)
        },
        {
            path: '/myCoupon',
            name: 'MyCoupon',
            component: resolve => require(['@/pages/travel/coupon'], resolve)
        },
        {
            path: '/selectYou',
            name: 'SelectYou',
            component: resolve => require(['@/pages/index/selectYou'], resolve)
        },
        {
            path: '/addChu',
            name: 'AddChu',
            component: resolve => require(['@/pages/index/chuAdd'], resolve)
        },
        {
            path: '/express',
            name: 'Express',
            component: resolve => require(['@/pages/feature/express'], resolve)
        },
        {
            path: '/refund',
            name: 'Refund',
            component: resolve => require(['@/pages/feature/refund'], resolve)
        },
        {
            // 拼团详情
            path: '/collage',
            name: 'Collage',
            component: resolve => require(['@/pages/collage/index'], resolve),
        },
        {
            // 拼团中
            path: '/collageIn',
            name: 'CollageIn',
            component: resolve => require(['@/pages/collage/collageIn'], resolve)
        },
        // 拼团列表
        {
            path: '/collageList',
            name: 'CollageList',
            component: resolve => require(['@/pages/collage/collageList'], resolve)
        },
        // 限时抢购列表
        {
            path: '/buyList',
            name: 'BuyList',
            component: resolve => require(['@/pages/collage/buyList'], resolve)
        },
        //我的拼团
        {
            path: '/myCollage',
            name: 'MyCollage',
            component: resolve => require(['@/pages/collage/myCollage'], resolve)
        },
        //我的拼团付款
        {
            path: '/collagePlace',
            name: 'CollagePlace',
            component: resolve => require(['@/pages/collage/collagePlace'], resolve)
        },
        //拼团订单支付
        {
            path: '/collagePay',
            name: 'CollagePay',
            component: resolve => require(['@/pages/collage/collagePay'], resolve)
        },
        //虚拟拼团
        {
            path: '/xuni',
            name: 'Xuni',
            component: resolve => require(['@/pages/xuni/index'], resolve)
        }
    ],
    scrollBehavior(to, from, savedPosition) {
        if (savedPosition) {
            return savedPosition
        } else {
            if (from.meta.keepAlive) {
                // 在触发路由切换时，如果当前页面需要缓存数据，那么在其路由的meta.savedPostion中保存当前页面的滚动位置数据
                from.meta.savedPosition = document.body.scrollTop || document.documentElement.scrollTop;
            }
            // 切换路由时，检测其meta.savedPosition, 如果有值则将其滚动到缓存位置       
            return { x: 0, y: to.meta.savedPosition || 0 }
        }
    }
})